package com.itheima.health.util;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.profile.DefaultProfile;
import com.google.gson.Gson;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;

@Slf4j
public class AliSmsUtil {

    public Boolean sendMess(String phoneNumbers,String code){
        DefaultProfile profile = DefaultProfile.getProfile("cn-beijing", "LTAI5tM4znjuZE6k9oiAMS9d", "sYy6OneCDslx0nCzFY1QQwHven6Khn");
        IAcsClient client = new DefaultAcsClient(profile);
        // 创建API请求并设置参数
        SendSmsRequest request = new SendSmsRequest();
        request.setSignName("巩鑫宇的个人网站");
        request.setTemplateCode("SMS_460780914");
        request.setPhoneNumbers(phoneNumbers);
        request.setTemplateParam("{\"code\":\""+code+"\"}");
        try {
            SendSmsResponse response = client.getAcsResponse(request);
            System.out.println(new Gson().toJson(response));
            log.info("发送成功");
            return true;
        } catch (Exception e){
            return false;
        }
    }

/*    public Boolean sendMessNote(String telephone, String orderDate) {
        DefaultProfile profile = DefaultProfile.getProfile("cn-beijing", "LTAI5tM4znjuZE6k9oiAMS9d", "sYy6OneCDslx0nCzFY1QQwHven6Khn");
        IAcsClient client = new DefaultAcsClient(profile);
        // 创建API请求并设置参数
        SendSmsRequest request = new SendSmsRequest();
        request.setSignName("巩鑫宇的博客");
        request.setTemplateCode("SMS_460890091");
        request.setPhoneNumbers(telephone);
        request.setTemplateParam("{\"orderDate\":\""+orderDate+"\"}");
        try {
            SendSmsResponse response = client.getAcsResponse(request);
            System.out.println(new Gson().toJson(response));
            log.info("发送成功");
            return true;
        } catch (Exception e){
            return false;
        }
    }*/
}
